#! /usr/bin/env python
#coding=utf-8

"""

    2011 Boris Tatarintsev

    Auxiliary functions
    
"""

"""

# old data structure legacy code

def getUserSubtree(username, next):
    # returns the sub hash of a hash to which
    # this user belongs
    stack = []
    result = []
    if not (type(next) is dict):
        return result
    k = zip(next.keys(), [0]*len(next.keys()))
    while(True):
        if k != None:            
            for key in k:
                if key[0] == username:
                    result.append( (next[key[0]], key[1]) )
                stack.append( (next[key[0]], key[1]) )
        if len(stack) > 0:
            next, lvl = stack.pop()
            if type(next) is dict:
                k = zip(next.keys(), [lvl + 1]*len(next.keys()))
            else:
                k = None
                continue
        else:  return result
    return result
   

def isFlat(hash):
    for item in hash.keys():
        if hash[item] != {} and type(hash[item]) is dict:
            return False
    return True

"""